home *** CD-ROM | disk | FTP | other *** search
/ Champak 49 / Volume 49 - JOGO DISK .iso / Games / evilswitch.swf / scripts / DefineSprite_15_mc.tile / frame_1 / DoAction.as
Encoding:
Text File  |  2007-09-27  |  5.1 KB  |  202 lines

  1. this.init = function()
  2. {
  3.    this._x = this.pPos.x;
  4.    this._y = this.pPos.y;
  5.    if(this._parent._name == "grid_mc")
  6.    {
  7.       var _loc2_ = Math.floor(this.pNum / 8);
  8.       var _loc3_ = this.pNum - Math.floor(this.pNum / 8) * 8;
  9.       this._y = -80 - (8 - _loc2_) * 100 - _loc3_ * 15;
  10.    }
  11.    else
  12.    {
  13.       this._y -= 160;
  14.    }
  15.    this.pSpeedX = 0;
  16.    this.pSpeedY = 0;
  17.    this.pLandTest = false;
  18.    this.pCenter = new Object();
  19.    this.pCenter.x = this.pCenter.y = 0;
  20.    this.pAngle = 0;
  21.    this.pAngleStep = 0.6283185307179586;
  22.    this.pDirection = 1;
  23.    this.pDepth = this.getDepth();
  24.    this.pState = 0;
  25.    this.gotoAndStop(this.pColour + 1);
  26. };
  27. this.scaleTile = function()
  28. {
  29.    this.pSpeedY = 0;
  30.    this.pState = 4;
  31.    this.addEnterFrame();
  32. };
  33. this.destroyTile = function()
  34. {
  35.    this.pSpeedX = 0;
  36.    this.pSpeedY = Math.random() * -8;
  37.    this.pState = 5;
  38.    this.addEnterFrame();
  39. };
  40. this.startTile = function()
  41. {
  42.    this._x = this.pPos.x;
  43.    this._y = this.pPos.y;
  44.    this._xscale = 100;
  45.    this._yscale = 100;
  46.    this._alpha = 100;
  47.    var _loc2_ = Math.floor(this.pNum / 8);
  48.    var _loc3_ = this.pNum - Math.floor(this.pNum / 8) * 8;
  49.    this.pSpeedY = 15;
  50.    this.pLandTest = false;
  51.    this.pState = 1;
  52.    this.addEnterFrame();
  53.    this.gotoAndStop(this.pColour + 1);
  54.    this._parent.tileDropDone();
  55. };
  56. this.renewTile = function(n, c)
  57. {
  58.    this.pPos.y = -140 + 40 * Math.floor(n / 8);
  59.    this._x = pPos.x;
  60.    this._y = -250;
  61.    this.pNum = n;
  62.    this.pColour = c;
  63.    this.gotoAndStop(this.pColour + 1);
  64.    this.pSpeedY = 0;
  65.    this.pState = 1;
  66.    this.addEnterFrame();
  67. };
  68. this.hideTile = function()
  69. {
  70.    this._y = this.pPos.y - 160;
  71.    this.pState = 0;
  72.    this.removeEnterFrame();
  73. };
  74. this.placeTile = function(tY, tC)
  75. {
  76.    this._xscale = 100;
  77.    this._yscale = 100;
  78.    this._y = this.pPos.y - tY;
  79.    this.pColour = tC;
  80.    this.gotoAndStop(this.pColour + 1);
  81.    this.pSpeedY = 0;
  82.    this.pState = 1;
  83.    this.addEnterFrame();
  84. };
  85. this.dropTile = function(d, tId)
  86. {
  87.    this.pPos.y += d * 40;
  88.    this.pNum += d * 8;
  89.    this.pSpeedY = 0;
  90.    this.pState = 1;
  91.    this.addEnterFrame();
  92. };
  93. this.removeTile = function()
  94. {
  95.    this.pSpeedY = 0;
  96.    this.pState = 3;
  97.    this.addEnterFrame();
  98. };
  99. this.moveTile = function(aX, aY, aDir, aNewNum)
  100. {
  101.    this.pCenter.x = this.pPos.x - (this.pPos.x - aX) / 2;
  102.    this.pCenter.y = this.pPos.y - (this.pPos.y - aY) / 2;
  103.    this.pDirection = aDir;
  104.    switch(true)
  105.    {
  106.       case this.pPos.x < aX:
  107.          this.pAngle = -3.141592653589793;
  108.          break;
  109.       case this.pPos.x > aX:
  110.          this.pAngle = 0;
  111.          break;
  112.       case this.pPos.y < aY:
  113.          this.pAngle = -1.5707963267948966;
  114.          break;
  115.       case this.pPos.y > aY:
  116.          this.pAngle = 1.5707963267948966;
  117.    }
  118.    this.pPos.x = aX;
  119.    this.pPos.y = aY;
  120.    this.pNum = aNewNum;
  121.    this.pState = 2;
  122.    this.addEnterFrame();
  123. };
  124. this.removeEnterFrame = function()
  125. {
  126.    delete this.onEnterFrame;
  127. };
  128. this.addEnterFrame = function()
  129. {
  130.    this.onEnterFrame = function()
  131.    {
  132.       switch(this.pState)
  133.       {
  134.          case 1:
  135.             this.pSpeedY = Math.min(this.pSpeedY + 2,50);
  136.             this._y += this.pSpeedY;
  137.             if(this._y >= this.pPos.y)
  138.             {
  139.                this._y = this.pPos.y;
  140.                this.pState = 0;
  141.                this._parent.tileDropDone();
  142.             }
  143.             break;
  144.          case 2:
  145.             this.pAngle += this.pAngleStep * this.pDirection;
  146.             this._x = this.pCenter.x + Math.cos(this.pAngle) * 20;
  147.             this._y = this.pCenter.y + Math.sin(this.pAngle) * 20;
  148.             if(Math.abs(this._x - this.pPos.x) < 1)
  149.             {
  150.                if(Math.abs(this._y - this.pPos.y) < 1)
  151.                {
  152.                   this._x = this.pPos.x;
  153.                   this._y = this.pPos.y;
  154.                   this.pState = 0;
  155.                   this._parent.tileSwapDone();
  156.                }
  157.             }
  158.             break;
  159.          case 3:
  160.             this.pSpeedY += 10;
  161.             this._xscale -= this.pSpeedY;
  162.             this._yscale -= this.pSpeedY;
  163.             if(this._xscale <= 0)
  164.             {
  165.                this._xscale = 100;
  166.                this._yscale = 100;
  167.                this._y = -180;
  168.                this.pState = 0;
  169.                this._parent.tileClearDone();
  170.             }
  171.             break;
  172.          case 4:
  173.             this.pSpeedY += 5;
  174.             this._xscale -= this.pSpeedY;
  175.             this._yscale -= this.pSpeedY;
  176.             if(this._xscale <= 0)
  177.             {
  178.                this._xscale = 0;
  179.                this._yscale = 0;
  180.                this.pState = 0;
  181.                this._parent.tileScaleDone();
  182.             }
  183.             break;
  184.          case 5:
  185.             this.pSpeedY = Math.min(this.pSpeedY + 2,50);
  186.             this._x += this.pSpeedX;
  187.             this._y += this.pSpeedY;
  188.             if(this._y >= 180)
  189.             {
  190.                this.pState = 0;
  191.                this._parent.tileDestroyDone();
  192.             }
  193.       }
  194.       if(pState == 0)
  195.       {
  196.          this.removeEnterFrame();
  197.       }
  198.    };
  199. };
  200. this.init();
  201. stop();
  202.